<?php
/**
 * Created by PhpStorm.
 * User: small
 * Date: 2018/11/5
 * Time: 21:31
 */

namespace app\api\controller;
use think\Controller;
use think\Db;
use think\Request;

class Game extends Controller
{
    //获取游戏的投注记录（猜大小）
    public function Set_size_log(){

        $res = Request::instance();

        if ($res->isPost()){

            $amount = $res->param('amount');//投注金额

            $isbig = $res->param('isbig');//投注内容

            $jieguo = $res->param('jieguo');//开奖结果

            $jiangjin = $res->param('jiangjin');//奖金

            $xingyunnum = $res->param('xingyunnum');//幸运数

            $xinyunjiang = $res->param('xinyunjiang');//幸运奖

            $uname = $res->param('uname');//玩家账号

            $address = $res->param('address');//钱包地址

            $hash = $res->param('hash');//本次哈希

           if ( Db::name('game')->insert([

               'uname'=> $uname,

               'hash' => $hash,

               'results' => $jieguo,

               'type' => 'daxiao',

               'xiazhuinfo' => $isbig,

               'jiangjin' => $jiangjin,

               'xinyunnum' => $xingyunnum,

               'xinyunjiang' => $xinyunjiang,

               'xiazhuinum' => $amount,

               'address' => $address,

               'time' => time(),

           ])){

               echo json_encode(['zt'=>1,'msg'=>'本次下注成功']);

           }else{

                echo json_encode(['zt'=>0,'msg'=>'记录储存失败!']);

           }

        }else{

            echo json_encode(['zt'=>2,'msg'=>'Error']);

        }

    }
    //获取最新的30条记录(全部记录)30条
    public function Get_game_log(){

        $data = Db::name('game')->order('time desc')->limit(30)->select();

        if ($data){

            echo json_encode(['zt'=>1,'msg'=>'获取失败','data'=>$data]);

        }else{

            echo json_encode(['zt'=>0,'msg'=>'获取失败','data'=>0]);

        }



    }

}